let data = localStorage.getItem('collect')
let collectObj = document.querySelector('.paid-con')
let html = ''
if (data) {
    data=JSON.parse(data)
    Array.from(data).forEach((good)=>{
        html+=` <div>
        <div class="mijia-personal-product">
            <div class="mijia-personal-product-image mijia-personal-left"><img class=""
                    src="${good.src}"
                    alt=""></div><span class="mijia-personal-product-text-box mijia-personal-left">
                <div class="mijia-personal-has-price mijia-personal-product-name-box">
                    <p>${good.tips}</p>
                </div>
            </span>
        </div>
        <section class="mijia-personal-item-footer">
            <div class="mijia-personal-button-box mijia-personal-right mijia-personal-item-box"><span
                    class="m-btns m-btn-sm m-btn-gray collect-one" onclick="cancelFn(${good.id})" >取消收藏</span><sapn
                    class="m-btns m-btn-sm m-btn-gray collect-two" onclick="viewFn('${good.id}','${good.src}','${good.tips}','${good.price}','${good.img1}','${good.img2}','${good.img3}','${good.img4}')"
                   >查看商品</sapn></div>
        </section>
    </div>`
    })
    collectObj.innerHTML=html
} else {
    html = `<div class="c-img"></div>
    <p class="p-info">您还没有收藏任何产品</p>`
    collectObj.innerHTML=html
}

function cancelFn(id){
    layer.msg('取消收藏', {
        color: 'green',
        offset: "t",
    });
    let data=localStorage.getItem('collect')
    if(data){
        data=JSON.parse(data)
        Array.from(data).forEach((v,i)=>{
            if(v.id==id){
                data.splice(i,1)
            }
        })
        localStorage.setItem('collect',JSON.stringify(data))
        location.reload()
    }
}
function viewFn(id,src,tips,price,img1,img2,img3,img4){
    let goods={
        id,src,tips,price,img1,img2,img3,img4
    }
    goods=[goods]
    localStorage.setItem('now',JSON.stringify(goods))
    location.href='http://127.0.0.1:5500/xiaomiyoupin/good.html'
}